package com.wlyuan.open.scanner.application.factory;

import com.wlyuan.open.scanner.application.handler.incr.BaseIncrHandler;

import java.util.Collection;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author lijing
 * @description
 */
public final class IncrSyncHandler {

    /**
     * 增量同步实现类map
     */
    private static Map<String, BaseIncrHandler> incrementMap = new ConcurrentHashMap<>();

    public static BaseIncrHandler getEventListener(String syncType) {
        return incrementMap.get(syncType);
    }

    public static synchronized void initHandler(Collection<BaseIncrHandler> handlers) {
        Optional.ofNullable(handlers).ifPresent(
                hs -> {
                    hs.forEach(h -> {
                        String syncType = h.getSyncType();

                        incrementMap.put(syncType, h);

                    });
                }
        );
    }

}
